package ml.practicum.table;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class HeadedTableFactory {

	/*	public static HeadedTable<Feature<String>,List<BasicLogisticValue>>create(HeadedTable<String,String> input, File headerSettings){
		DynamicHeadedTable<Feature<String>, List<BasicLogisticValue>> result =
			new DynamicHeadedTable<Feature<String>,List<BasicLogisticValue>>(getFeatureHeader(input, headerSettings));
			for(List<String> row:input.getRows()){
				result.addRow(processRow(result.getHeader(), row));
			}
		return result;
	}*/
	
	/**
	 *  reads a csv file/table with a header
	 *  and returns a Table filled with strings
	 * @param fileName		 path of csv file
	 * @return HeadedTable<String,String> representing the table form the csv file;
	*/
	public static HeadedTable<String,String>create(String fileName){
		DynamicHeadedTable<String,String> result = null;
		try{
		BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName)); 
		for(String nextLine = bufferedReader.readLine(); nextLine != null; nextLine = bufferedReader.readLine()){
			String[] fields = nextLine.split(",");
			if (result == null){
					result = new DynamicHeadedTable<String,String>(fields);
			}else{
				result.addRow(fields);
			}
		}
		}catch(IOException e){
			e.printStackTrace();
		}
		return result;
	}
	
}
